// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyRemapAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyRemapAttributes
//
// Purpose:
//   Atts for Remap operator
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a RemapAttributes.
//
struct RemapAttributesObject
{
    PyObject_HEAD
    RemapAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewRemapAttributes(int);
std::string
PyRemapAttributes_ToString(const RemapAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetUseExtents())
        snprintf(tmpStr, 1000, "%suseExtents = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%suseExtents = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sstartX = %g\n", prefix, atts->GetStartX());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sendX = %g\n", prefix, atts->GetEndX());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scellsX = %d\n", prefix, atts->GetCellsX());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sstartY = %g\n", prefix, atts->GetStartY());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sendY = %g\n", prefix, atts->GetEndY());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scellsY = %d\n", prefix, atts->GetCellsY());
    str += tmpStr;
    if(atts->GetIs3D())
        snprintf(tmpStr, 1000, "%sis3D = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sis3D = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sstartZ = %g\n", prefix, atts->GetStartZ());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sendZ = %g\n", prefix, atts->GetEndZ());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%scellsZ = %d\n", prefix, atts->GetCellsZ());
    str += tmpStr;
    const char *variableType_names = "intrinsic, extrinsic";
    switch (atts->GetVariableType())
    {
      case RemapAttributes::intrinsic:
          snprintf(tmpStr, 1000, "%svariableType = %sintrinsic  # %s\n", prefix, prefix, variableType_names);
          str += tmpStr;
          break;
      case RemapAttributes::extrinsic:
          snprintf(tmpStr, 1000, "%svariableType = %sextrinsic  # %s\n", prefix, prefix, variableType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    return str;
}

static PyObject *
RemapAttributes_Notify(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_SetUseExtents(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the useExtents in the object.
    obj->data->SetUseExtents(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetUseExtents(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetUseExtents()?1L:0L);
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetStartX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the startX in the object.
    obj->data->SetStartX(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetStartX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetStartX());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetEndX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the endX in the object.
    obj->data->SetEndX(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetEndX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetEndX());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetCellsX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the cellsX in the object.
    obj->data->SetCellsX(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetCellsX(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCellsX()));
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetStartY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the startY in the object.
    obj->data->SetStartY(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetStartY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetStartY());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetEndY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the endY in the object.
    obj->data->SetEndY(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetEndY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetEndY());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetCellsY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the cellsY in the object.
    obj->data->SetCellsY(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetCellsY(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCellsY()));
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetIs3D(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the is3D in the object.
    obj->data->SetIs3D(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetIs3D(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetIs3D()?1L:0L);
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetStartZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the startZ in the object.
    obj->data->SetStartZ(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetStartZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetStartZ());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetEndZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the endZ in the object.
    obj->data->SetEndZ(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetEndZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetEndZ());
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetCellsZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the cellsZ in the object.
    obj->data->SetCellsZ(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetCellsZ(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetCellsZ()));
    return retval;
}

/*static*/ PyObject *
RemapAttributes_SetVariableType(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 2)
    {
        std::stringstream ss;
        ss << "An invalid variableType value was given." << std::endl;
        ss << "Valid values are in the range [0,1]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " intrinsic";
        ss << ", extrinsic";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the variableType in the object.
    obj->data->SetVariableType(RemapAttributes::VariableTypes(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
RemapAttributes_GetVariableType(PyObject *self, PyObject *args)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetVariableType()));
    return retval;
}



PyMethodDef PyRemapAttributes_methods[REMAPATTRIBUTES_NMETH] = {
    {"Notify", RemapAttributes_Notify, METH_VARARGS},
    {"SetUseExtents", RemapAttributes_SetUseExtents, METH_VARARGS},
    {"GetUseExtents", RemapAttributes_GetUseExtents, METH_VARARGS},
    {"SetStartX", RemapAttributes_SetStartX, METH_VARARGS},
    {"GetStartX", RemapAttributes_GetStartX, METH_VARARGS},
    {"SetEndX", RemapAttributes_SetEndX, METH_VARARGS},
    {"GetEndX", RemapAttributes_GetEndX, METH_VARARGS},
    {"SetCellsX", RemapAttributes_SetCellsX, METH_VARARGS},
    {"GetCellsX", RemapAttributes_GetCellsX, METH_VARARGS},
    {"SetStartY", RemapAttributes_SetStartY, METH_VARARGS},
    {"GetStartY", RemapAttributes_GetStartY, METH_VARARGS},
    {"SetEndY", RemapAttributes_SetEndY, METH_VARARGS},
    {"GetEndY", RemapAttributes_GetEndY, METH_VARARGS},
    {"SetCellsY", RemapAttributes_SetCellsY, METH_VARARGS},
    {"GetCellsY", RemapAttributes_GetCellsY, METH_VARARGS},
    {"SetIs3D", RemapAttributes_SetIs3D, METH_VARARGS},
    {"GetIs3D", RemapAttributes_GetIs3D, METH_VARARGS},
    {"SetStartZ", RemapAttributes_SetStartZ, METH_VARARGS},
    {"GetStartZ", RemapAttributes_GetStartZ, METH_VARARGS},
    {"SetEndZ", RemapAttributes_SetEndZ, METH_VARARGS},
    {"GetEndZ", RemapAttributes_GetEndZ, METH_VARARGS},
    {"SetCellsZ", RemapAttributes_SetCellsZ, METH_VARARGS},
    {"GetCellsZ", RemapAttributes_GetCellsZ, METH_VARARGS},
    {"SetVariableType", RemapAttributes_SetVariableType, METH_VARARGS},
    {"GetVariableType", RemapAttributes_GetVariableType, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
RemapAttributes_dealloc(PyObject *v)
{
   RemapAttributesObject *obj = (RemapAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *RemapAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyRemapAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "useExtents") == 0)
        return RemapAttributes_GetUseExtents(self, NULL);
    if(strcmp(name, "startX") == 0)
        return RemapAttributes_GetStartX(self, NULL);
    if(strcmp(name, "endX") == 0)
        return RemapAttributes_GetEndX(self, NULL);
    if(strcmp(name, "cellsX") == 0)
        return RemapAttributes_GetCellsX(self, NULL);
    if(strcmp(name, "startY") == 0)
        return RemapAttributes_GetStartY(self, NULL);
    if(strcmp(name, "endY") == 0)
        return RemapAttributes_GetEndY(self, NULL);
    if(strcmp(name, "cellsY") == 0)
        return RemapAttributes_GetCellsY(self, NULL);
    if(strcmp(name, "is3D") == 0)
        return RemapAttributes_GetIs3D(self, NULL);
    if(strcmp(name, "startZ") == 0)
        return RemapAttributes_GetStartZ(self, NULL);
    if(strcmp(name, "endZ") == 0)
        return RemapAttributes_GetEndZ(self, NULL);
    if(strcmp(name, "cellsZ") == 0)
        return RemapAttributes_GetCellsZ(self, NULL);
    if(strcmp(name, "variableType") == 0)
        return RemapAttributes_GetVariableType(self, NULL);
    if(strcmp(name, "intrinsic") == 0)
        return PyInt_FromLong(long(RemapAttributes::intrinsic));
    if(strcmp(name, "extrinsic") == 0)
        return PyInt_FromLong(long(RemapAttributes::extrinsic));



    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyRemapAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyRemapAttributes_methods[i].ml_name),
                PyString_FromString(PyRemapAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyRemapAttributes_methods, self, name);
}

int
PyRemapAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "useExtents") == 0)
        obj = RemapAttributes_SetUseExtents(self, args);
    else if(strcmp(name, "startX") == 0)
        obj = RemapAttributes_SetStartX(self, args);
    else if(strcmp(name, "endX") == 0)
        obj = RemapAttributes_SetEndX(self, args);
    else if(strcmp(name, "cellsX") == 0)
        obj = RemapAttributes_SetCellsX(self, args);
    else if(strcmp(name, "startY") == 0)
        obj = RemapAttributes_SetStartY(self, args);
    else if(strcmp(name, "endY") == 0)
        obj = RemapAttributes_SetEndY(self, args);
    else if(strcmp(name, "cellsY") == 0)
        obj = RemapAttributes_SetCellsY(self, args);
    else if(strcmp(name, "is3D") == 0)
        obj = RemapAttributes_SetIs3D(self, args);
    else if(strcmp(name, "startZ") == 0)
        obj = RemapAttributes_SetStartZ(self, args);
    else if(strcmp(name, "endZ") == 0)
        obj = RemapAttributes_SetEndZ(self, args);
    else if(strcmp(name, "cellsZ") == 0)
        obj = RemapAttributes_SetCellsZ(self, args);
    else if(strcmp(name, "variableType") == 0)
        obj = RemapAttributes_SetVariableType(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
RemapAttributes_print(PyObject *v, FILE *fp, int flags)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)v;
    fprintf(fp, "%s", PyRemapAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
RemapAttributes_str(PyObject *v)
{
    RemapAttributesObject *obj = (RemapAttributesObject *)v;
    return PyString_FromString(PyRemapAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *RemapAttributes_Purpose = "Atts for Remap operator";
#else
static char *RemapAttributes_Purpose = "Atts for Remap operator";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(RemapAttributesType,         \
                  "RemapAttributes",           \
                  RemapAttributesObject,       \
                  RemapAttributes_dealloc,     \
                  RemapAttributes_print,       \
                  PyRemapAttributes_getattr,   \
                  PyRemapAttributes_setattr,   \
                  RemapAttributes_str,         \
                  RemapAttributes_Purpose,     \
                  RemapAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
RemapAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &RemapAttributesType
         || Py_TYPE(other) != &RemapAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    RemapAttributes *a = ((RemapAttributesObject *)self)->data;
    RemapAttributes *b = ((RemapAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static RemapAttributes *defaultAtts = 0;
static RemapAttributes *currentAtts = 0;

static PyObject *
NewRemapAttributes(int useCurrent)
{
    RemapAttributesObject *newObject;
    newObject = PyObject_NEW(RemapAttributesObject, &RemapAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new RemapAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new RemapAttributes(*defaultAtts);
    else
        newObject->data = new RemapAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapRemapAttributes(const RemapAttributes *attr)
{
    RemapAttributesObject *newObject;
    newObject = PyObject_NEW(RemapAttributesObject, &RemapAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (RemapAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
RemapAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewRemapAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef RemapAttributesMethods[] = {
    {"RemapAttributes", RemapAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *RemapAttributesObserver = 0;

std::string
PyRemapAttributes_GetLogString()
{
    std::string s("RemapAtts = RemapAttributes()\n");
    if(currentAtts != 0)
        s += PyRemapAttributes_ToString(currentAtts, "RemapAtts.", true);
    return s;
}

static void
PyRemapAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("RemapAtts = RemapAttributes()\n");
        s += PyRemapAttributes_ToString(currentAtts, "RemapAtts.", true);
        cb(s);
    }
}

void
PyRemapAttributes_StartUp(RemapAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyRemapAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(RemapAttributesObserver == 0)
    {
        RemapAttributesObserver = new ObserverToCallback(subj,
            PyRemapAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyRemapAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete RemapAttributesObserver;
    RemapAttributesObserver = 0;
}

PyMethodDef *
PyRemapAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return RemapAttributesMethods;
}

bool
PyRemapAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &RemapAttributesType);
}

RemapAttributes *
PyRemapAttributes_FromPyObject(PyObject *obj)
{
    RemapAttributesObject *obj2 = (RemapAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyRemapAttributes_New()
{
    return NewRemapAttributes(0);
}

PyObject *
PyRemapAttributes_Wrap(const RemapAttributes *attr)
{
    return WrapRemapAttributes(attr);
}

void
PyRemapAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    RemapAttributesObject *obj2 = (RemapAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyRemapAttributes_SetDefaults(const RemapAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new RemapAttributes(*atts);
}

